import React from 'react'
import {Table, Button, Switch} from 'antd'
import {Link} from 'react-router';
import StateMixin from 'reflux-state-mixin';
import SrvItemStore from 'pages/serviceitems/stores/serviceItemStore.js';

export default React.createClass({
  mixins: [StateMixin.connect(SrvItemStore)],
  getInitialState() {
    return {
    };
  },
  handleDelete(id) {
    this.props.deleteItem(id);
  },
  changeStatus(id,checked) {
    this.props.changeStatus(id,checked);
  },
  render() {
    const columns = [{
      title: '服务项名称',
      dataIndex: 'name',
      key: 'name',
      render: (text, record) => (
          <Link to={'/service/serviceitems/' + record.id}>{text}</Link>
        )
    }, {
      title: '描述',
      dataIndex: 'description',
      key: 'description',
    }, {
      title: '标签',
      dataIndex: 'tags',
      key: 'tagse',
    }, {
      title: '使用状态',
      dataIndex: 'status',
      key: 'status',
      render:(text, record) => (
          <Switch
            checkedChildren="上线" unCheckedChildren="下线"  
            checked={record.status === 1} onChange={this.changeStatus.bind(this,record.id)}/>
        )
    },{
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      render: (text, record) => {
        return USER_INFO.root
            ? <div>
                <Button icon='delete' type="ghost"
                  disabled={record.status === 1}
                  onClick={this.handleDelete.bind(this,record.id)}
                  className="lidel">删除</Button>
               </div>
            : null
      }
    }];
    return (
      <div className="srvItem-card-warp">
        <Table rowKey="id" pagination={false}
          dataSource={this.state.items} columns={columns} />
      </div>
    )
  }
})
